/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import muddb.PermisionLevelEnum;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "user_account" )
@NamedQueries(
  {
    @NamedQuery( name = "UserAccount.findByUserId",
                  query = "SELECT u FROM UserAccount u WHERE u.userId = :userId" ),
    @NamedQuery( name = "UserAccount.findByUserLogon",
                  query = "SELECT u FROM UserAccount u WHERE u.userLogon = :userLogon" ),
    @NamedQuery( name = "UserAccount.findByUserName",
                  query = "SELECT u FROM UserAccount u WHERE u.userName = :userName" ),
    @NamedQuery( name = "UserAccount.findByUserPswd",
                  query = "SELECT u FROM UserAccount u WHERE u.userPswd = :userPswd" ),
    @NamedQuery( name = "UserAccount.findByBanExprTs",
                  query = "SELECT u FROM UserAccount u WHERE u.banExprTs = :banExprTs" ) } )
public class UserAccount implements Serializable {
  private static final long serialVersionUID = 1L;
  private Integer userId;
  private String userLogon;
  private String userName;
  private String userPswd;
  private Date banExprTs;
  private Collection<UserChar> userCharCollection;
  private PermisionLevelEnum permission;


  public UserAccount() {
  }


  public UserAccount( Integer userId ) {
    this.userId = userId;
  }


  public UserAccount( Integer userId, String userLogon, String userName ) {
    this.userId = userId;
    this.userLogon = userLogon;
    this.userName = userName;
  }


  @Id
  @GeneratedValue( strategy = GenerationType.SEQUENCE )
  @Column( name = "user_id", nullable = false )
  public Integer getUserId() {
    return userId;
  }


  public void setUserId( Integer userId ) {
    this.userId = userId;
  }


  @Column( name = "user_logon", length = 12, nullable = false, unique=true )
  public String getUserLogon() {
    return userLogon;
  }


  public void setUserLogon( String userLogon ) {
    this.userLogon = userLogon;
  }


  @Column( name = "user_name", length = 50, nullable = false )
  public String getUserName() {
    return userName;
  }


  public void setUserName( String userName ) {
    this.userName = userName;
  }


  @Column( name = "user_pswd", length = 20 )
  public String getUserPswd() {
    return userPswd;
  }


  public void setUserPswd( String userPswd ) {
    this.userPswd = userPswd;
  }


  @Column( name = "ban_expr_ts" )
  @Temporal( TemporalType.TIMESTAMP )
  public Date getBanExprTs() {
    return banExprTs;
  }


  public void setBanExprTs( Date banExprTs ) {
    this.banExprTs = banExprTs;
  }


  @OneToMany( cascade = CascadeType.ALL, mappedBy = "userAccount" )
  public Collection<UserChar> getUserCharCollection() {
    return userCharCollection;
  }


  public void setUserCharCollection( Collection<UserChar> userCharCollection ) {
    this.userCharCollection = userCharCollection;
  }


  @Column( name = "perm_lvl" )
  public PermisionLevelEnum getPermission() {
    return permission;
  }


  public void setPermission( PermisionLevelEnum permission ) {
    this.permission = permission;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += ( userId != null ? userId.hashCode() : 0 );
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof UserAccount ) ) {
      return false;
    }
    UserAccount other = (UserAccount) object;
    if ( ( this.userId == null && other.userId != null ) || ( this.userId != null && !this.userId.equals( other.userId ) ) ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.UserAccount[userId=" + userId + "]";
  }

}
